package mux

import (
	"errors"
	"net/http"

	"net/url"
)

const MUX_URL = "http://localhost:2112"

func ListenHostname(hostname string, urlstr string) error {

	values := url.Values{}
	values.Set("hostname", hostname)
	values.Set("url", urlstr)
	resp, err := http.PostForm(MUX_URL+"/register", values)

	if err != nil {
		return err
	}

	if resp.StatusCode != 200 {
		return errors.New("could not register hostname listener")
	}

	return nil
}
